﻿'''
Created on May 10, 2011

@author: Jialai_Zhu
'''
key2=[u'中国股票证券发行管理中心优秀股票信息网站',u'入会指南']
def update_qs_key():
    import db_result
    qs_file=db_result.gb2312file('qs.key')
    DB_QUERY_KEYWORD=db_result.mongo_query_base(db_name='zq',table_name='keyword')
    items=[]
    DB_QS_S=db_result.mongo_query_base(db_name='zq',table_name='QS_S')
    DB_QS_F=db_result.mongo_query_base(db_name='zq',table_name='QS_F')     
    QS_S=[]
    for i in DB_QS_S.find({},0):
        QS_S.append(i['name'])
    QS_F=[]
    for i in DB_QS_F.find({},0):
        QS_F.append(i['name'])  
    KEY=[]
    def add_key(LIST):
        for k in LIST:
            for i in key2:
                try:qs_file.writeln((u'"%s" "%s"')%(i,k))
                except:pass
                db_result.func_append_list(KEY,(u'"%s" "%s"')%(i,k),lambda x,y:x==y)
    add_key(QS_S)
    add_key(QS_F)
    for i in KEY:
        DB_QUERY_KEYWORD.insert({'key':i,'date':'','result':0,'today':0,'type':1})
def update_qs():    
    from db_result import *
    items=[]
    for i in DB_QUERY_DAILY.find({}, 0):
        items.append(i['title'])      
    f=gb2312file('nomatch.txt')   
    x=extract_fake_zq() 
    QS_S=[]
    for i in DB_QS_S.find({},0):
        QS_S.append(i['name'])
    QS_F=[]
    for i in DB_QS_F.find({},0):
        QS_F.append(i['name'])    
    for string in items:
        try:
            stringU=get_unicode(string)            
            r=x.gettype(stringU)
            if len(r['type']):
                func_append_list(QS_S,r['type'],lambda x,y:x==y)
            if len(r['type']):
                func_append_list(QS_F,r['name'],lambda x,y:x==y)                
            f.writeln(u'%s,%s'%(r['name'],r['type']))
            continue
        except Exception,ex:
            pass
    for i in QS_S:
        DB_QS_S.insert({'name':i})
    for i in QS_F:
        DB_QS_F.insert({'name':i})
if __name__ == '__main__':
    update_qs_key()
    pass